package com.urtime.util;

public class StringUtil {     
	private static String[][] FilterChars={{"<","&lt;"},{">","&gt;"},{" ","&nbsp;"},{"\"","&quot;"},{"&","&amp;"},   
		{"/","&#47;"},{"\\","&#92;"},{"\n","<br>"}};   

	private static String[][] FilterScriptChars={{"\n","\'+\'\\n\'+\'"},   
		{"\r"," "},{"\\","\'+\'\\\\\'+\'"},   
		{"\'","\'+\'\\\'\'+\'"}};   

	public static String stringConnect(String[] strings,String spilit_sign){   
		String str="";   
		for(int i=0;i<strings.length;i++){   
			str+=strings[i]+spilit_sign;   
		}   
		return str;   
	}   


	public static String stringFilter(String str){   
		String[] str_arr=stringSpilit(str,"");   
		for(int i=0;i<str_arr.length;i++){   
			for(int j=0;j<FilterChars.length;j++){   
				if(FilterChars[j][0].equals(str_arr[i]))   
					str_arr[i]=FilterChars[j][1];   
			}   
		}   
		return (stringConnect(str_arr,"")).trim();   
	}   


	public static String stringFilterScriptChar(String str){   
		String[] str_arr=stringSpilit(str,"");   
		for(int i=0;i<str_arr.length;i++){   
			for (int j = 0; j < FilterScriptChars.length; j++) {   
				if (FilterScriptChars[j][0].equals(str_arr[i]))   
					str_arr[i] = FilterScriptChars[j][1];   
			}   
		}   
		return(stringConnect(str_arr,"")).trim();   
	}   


	public static String[] stringSpilit(String str,String spilit_sign){   
		String[] spilit_string=str.split(spilit_sign);   
		if(spilit_string[0].equals(""))   
		{   
			String[] new_string=new String[spilit_string.length-1];   
			for(int i=1;i<spilit_string.length;i++)   
				new_string[i-1]=spilit_string[i];   
			return new_string;   
		}   
		else  
			return spilit_string;   
	}   

	public static String stringTransCharset(String str){   
		String new_str=null;   
		try{   
			new_str=new String(str.getBytes("iso-8859-1"),"GBK");   
		}   
		catch(Exception e){   
			e.printStackTrace();   
		}   
		return new_str;   
	}   


}